//
//  MainViewController.m
//  ProductB
//
//  Created by lanou on 16/5/27.
//  Copyright © 2016年 ChenZheng. All rights reserved.
//

#import "MainViewController.h"
#import "MineTableViewCell.h"
#import "Font.h"
//头文件视图
#import "headerView.h"
#import "LoginViewController.h"
@interface MainViewController ()<UITableViewDelegate,UITableViewDataSource>
/**
 tableVIew
 */
@property (nonatomic , strong) UITableView *tableView;
/**
 命名数组
 */
@property (nonatomic , strong) NSArray *titleArray;
/**
 minetableViwecell 属性
 */
@property (nonatomic , strong) MineTableViewCell *mineCell;
/**
 imageViewArray
 */
@property (nonatomic , strong) NSArray *imageArray;
/*表头属性*/
@property (nonatomic , strong) headerView *headerView;
/*大scrollerView*/
@property (nonatomic , strong) UIScrollView *bigScrollerVeiw;
@end

@implementation MainViewController
#pragma mark--------界面将要出现----
//static int a = 1;
//-(void)viewWillAppear:(BOOL)animated{
//    LoginViewController *loginVc = [[LoginViewController alloc]init];
//    if (a == 1) {
//        [self.navigationController presentViewController:loginVc animated:YES completion:^{
//            
//        }];
//    }
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    //添加bigScrollerView
    [self addScrollerView];
    //添加tableVIew
    [self addTableView];
    //名称数组
    self.titleArray = @[@"收藏",@"夜间模式",@"清除缓存",@"服务条款"];
    UIImage *image1 = [UIImage imageNamed:@"collect"];
    UIImage *image2 = [UIImage imageNamed:@"nightMode"];
    UIImage *image3 = [UIImage imageNamed:@"cache"];
    UIImage *image4 = [UIImage imageNamed:@"font"];
    self.imageArray = @[image1,image2,image3,image4];
    //注册tableView
    [_tableView registerClass:[MineTableViewCell class] forCellReuseIdentifier:@"MineTableViewCell"];
    //表头视图
    self.headerView = [[headerView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight/3)];
    

    _headerView.backgroundColor = [UIColor redColor];
    [_bigScrollerVeiw addSubview:_headerView];
    
}
#pragma mark--------创建scrollerView----
-(void)addScrollerView{
    self.bigScrollerVeiw = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
//    _bigScrollerVeiw.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_bigScrollerVeiw];
}
#pragma mark--------添加tableView方法----
-(void)addTableView{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kHeight/3, kWidth, kHeight)];
    _tableView.backgroundColor = [UIColor blueColor];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_bigScrollerVeiw addSubview:_tableView];
}
#pragma mark--------tableview 的返回方法----
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.titleArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    self.mineCell = [tableView dequeueReusableCellWithIdentifier:@"MineTableViewCell"];
    self.mineCell.nameLabel.text = self.titleArray[indexPath.row];
    self.mineCell.imageV.image = self.imageArray[indexPath.row];
    self.mineCell.nameLabel.font = [UIFont fontWithName:[Font shareWithFont].fontName size:17];
    switch (indexPath.row) {
        case 0:
            
            break;
        case 1:
        {
            self.mineCell.pictureView.alpha = 0;
            self.mineCell.swithDN.alpha = 1;
            [self.mineCell.swithDN addTarget:self action:@selector(changeDN:) forControlEvents:(UIControlEventValueChanged)];
        }
            break;
        case 2:
        {
            self.mineCell.nameLabel.text = [NSString stringWithFormat:@"清除缓存(%@B)", [self getFileSize]];
            
        }
            break;
        case 3:
        {
            self.mineCell.tag = 6000;
        }
            break;
        default:
            break;
    }
    return self.mineCell;
}
#pragma mark--------黑白夜模式----
//创建通知
- (void)changeDN:(UISwitch *)switchButton {
    
    if (switchButton.isOn == YES) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"nightORday" object:@"黑夜模式"];
    }else {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"nightORday" object:@"白天模式"];
    }
    
}
#pragma mark--------缓存----
//计算缓存的方法
-(NSString *)getFileSize{
    NSLog(@"计算出缓存");
    return @"";
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
